import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:math2/controller/TexController.dart';

class QuestionInput extends GetView<TexController> {
  const QuestionInput({super.key});

  @override
  Widget build(BuildContext context) {

    // Get.put(TexController());

    final ImagePicker picker = ImagePicker();

    return Stack(
      children: <Widget>[
        TextField(
          //这里需要补充一个样例，否则别人真不知道咋输入
          keyboardType: TextInputType.multiline,
          minLines: 3,
          maxLines: null,
          decoration: const InputDecoration(
              border: OutlineInputBorder(), labelText: '在此处输入TeX方程式'),
          onChanged: (tex) {
            controller.setTex(tex.obs);
            // controller.tex = tex.obs;
            print(tex);
          },
        ),
        Positioned(
          top: 0,
          right: 0,
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              IconButton(
                icon: const Icon(Icons.camera_alt, color: Colors.redAccent,),
                onPressed: () async {
                  // Handle button press
                  final XFile? image = await picker.pickImage(source: ImageSource.gallery);
                  print(image!.path);
                },
              ),
              const SizedBox(width: 8), // Optional space between buttons
              IconButton(
                icon: const Icon(Icons.file_open, color: Colors.redAccent,),
                onPressed: () async {
                  // Handle button press
                  final XFile? photo = await picker.pickImage(source: ImageSource.camera);
                  print(photo!.path);
                },
              ),
            ],
          ),
        ),
      ],
    );
  }
}
